package com.dubbo;

public class VolitelExample {
    public static volatile boolean run = Boolean.TRUE;

    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread() {
            @Override
            public void run() {
                while (run) {
                    //System.out.println();
                    //prinln() contains synronnize key that guarantee the visiable of field run
                }
            }
        };
        thread.start();

        Thread.sleep(1000l);
        run = Boolean.FALSE;
        //即使在外面改变了值 thread线程也不会停下来  应为JIT优化 将run 仿如了缓存
    }
}


